package cn.community.system.service.impl;

import cn.community.system.domain.Association;
import cn.community.system.domain.Member;
import cn.community.system.domain.MemberVo;
import cn.community.system.exception.LogicException;
import cn.community.system.mapper.*;
import cn.community.system.query.QueryObject;
import cn.community.system.service.IMemberService;
import cn.community.system.service.IMemberVoService;
import cn.community.system.util.AssertUtils;
import cn.community.system.util.UserContext;
import cn.community.system.vo.AssoMemberVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

@Service
public class MemberVoServiceImpl implements IMemberVoService {
    @Autowired
    private MemberVoMapper memberVoMapper;

    @Autowired
    private AssociationMapper associationMapper;

    @Override
    public void save(MemberVo memberVo) {
        memberVoMapper.insert(memberVo);
    }

    @Override
    public void update(MemberVo memberVo) {
        memberVoMapper.update(memberVo);
    }

    @Override
    public List<MemberVo> listAll() {
        return memberVoMapper.selectAll();
    }

    @Override
    public List<MemberVo> selectByMemberId(Long id) {
        return memberVoMapper.selectByMemberId(id);
    }

    @Override
    public void apply(Long id, Integer hot) {
        Member member = UserContext.getCurrentMember();
        MemberVo memberVo = new MemberVo();
        memberVo.setAssoId(id);
        memberVo.setAssoname(associationMapper.selectByPrimaryKey(id).getUsername());
        memberVo.setMemberId(member.getId());
        memberVo.setName(member.getUsername());
        memberVo.setDeptname("普通成员");
        memberVo.setIsAgree(MemberVo.AGREE_NORMAL);
        this.save(memberVo);
    }

    @Override
    public void batchDelete(Long[] ids) {
        memberVoMapper.batchDelete(ids);
    }

    @Override
    public void bitchPass(Long[] ids) {
        for (Long id : ids) {
            memberVoMapper.passById(id,MemberVo.AGREE_YES,new Date());
        }
    }

    @Override
    public void deleteByPrimaryKey(Long id) {
        memberVoMapper.deleteByPrimaryKey(id);
    }
}
